define (require,exports,module)->
	Backbone.Model.extend
		default:
			id:0
			
		save:()->
			if @id == 0
				$.post "/api/user/create"

		read:(id,callback)-> 
			url = "/api/user/read";
			data = 
				id: id
			res = null;
			$.get url, 
				data, 
				(res)->
					if res.response.code == 0
						callback(res.data)
					else
						alert("error")
				'jsonp'

		update: ()->
			url = "/api/user/update";
			$.post url, data, 
				(res) ->
				if res.response.code == 0
					Backbone.Events.trigger("user-refresh", 1)
				else
					alert("error");
				
		},

		password: ()->
			var url = "/api/user/password";
			$.post url, data, 
				(res)->
					if res.response.code == 0
						Backbone.Events.trigger("user-refresh", 1)
					else 
						alert("error")

		create: (data)->
			url = "/api/user/create";
			$.post(url, data, function(res) {
				if (res.response.code == 0) {
					Backbone.Events.trigger("user-refresh", 1);
				} else {
					alert("error");
				}
			});
		},

		delete: function(data) {
			var url = "/api/user/delete";
			$.post(url, data, function(res) {
				if (res.response.code == 0) {
					Backbone.Events.trigger("user-refresh", 1);
				} else {
					alert("error");
				}
			});
		},

		list: function(pagecur, pageper) {
			var url = "/api/user/list";
			var data = {
				pagecur: pagecur,
				pageper: pageper
			}
			var res = null;
			$.get(url, data, function(res) {
				if (res.response.code == 0) {
					Backbone.Events.trigger("user-render", res.data);
				} else {
					alert("error");
				}
			});
		}
